package com.miniapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.miniapp.dto.PageDTO;
import com.miniapp.dto.SimpleSearchDTO;

import com.miniapp.entity.MiniProductEntity;

import com.miniapp.service.MiniProductService;
import com.miniapp.utils.R;

import java.util.Arrays;


/**
 * 
 *
 * @author linyuchi
 * @email xunli-03@163.com
 * @date 2018-05-18 16:32:05
 */
@RestController
@RequestMapping("miniapp/miniproduct")
public class MiniProductController extends AbstractController{
    @Autowired
    private MiniProductService miniProductService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(){

        SimpleSearchDTO simpleSearchDTO = getSearchDtoFromJqGrid();
        PageDTO<MiniProductEntity> page = miniProductService.findPageBySimpleSearch(simpleSearchDTO);

        return R.ok().put("page", page);

    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){

        MiniProductEntity miniProduct = miniProductService.getById(id);

        return R.ok().put("miniProduct", miniProduct);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody MiniProductEntity miniProduct){

        miniProductService.saveOrUpdate(miniProduct);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody MiniProductEntity miniProduct){

        miniProductService.saveOrUpdate(miniProduct);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){


        return  miniProductService.removeByIdsNoPrice(Arrays.asList(ids));
    }

}
